#pragma once

#include <iostream>
#include <functional>
#include <string>
#include "IntAddr.hpp"
class Reactor;

using handler_t = std::function<std::string(std::string&)>;

//给每个fd提供一个缓冲区
class Connection
{
public:
    Connection():_event(0),_owner(nullptr)
    {}

    virtual void Recver() = 0;
    virtual void Sender() = 0;
    virtual void Expecter() = 0;
    virtual int GetSockfd() = 0;
    void SetEvent(const uint32_t& event)
    {
        _event = event; 
    }
    uint32_t GetEvent()
    {
        return _event;
    }

    Reactor* GetOwner()
    {
        return _owner;
    }
    //设置回指指针
    void SetOwner(Reactor* owner)
    {
        _owner = owner;
    }
    void RegisterHandler(handler_t handler)
    {
        _handler = handler;
    }
    ~Connection()
    {}

private:

    //回指指针，指向Reactor
    Reactor *_owner;

    //关心事件
    uint32_t _event;
public:
    //回调函数
    handler_t _handler;
};